package com.hzbat.service.impl;  																		  

import java.util.ArrayList;
import java.util.List;																					

import org.slf4j.Logger;																				
import org.slf4j.LoggerFactory;																			
import org.springframework.beans.factory.annotation.Autowired;											
import org.springframework.stereotype.Service;															

import com.hzbat.dao.PmHzbatBatchesInfoMapper;																		
import com.hzbat.entity.PmHzbatBatchesInfo;																	
import com.hzbat.service.PmHzbatBatchesInfoService;																	
import com.github.pagehelper.PageInfo;																	
		
@Service("pmHzbatBatchesInfoServiceImpl")																	
public class PmHzbatBatchesInfoServiceImpl extends BasicServiceImpl<PmHzbatBatchesInfo> implements PmHzbatBatchesInfoService{	
		private static Logger logger = LoggerFactory.getLogger(PmHzbatBatchesInfoServiceImpl.class);				  

		@Autowired																							
		PmHzbatBatchesInfoMapper pmHzbatBatchesInfoMapper ;																  

		@Override																							
		public List<PmHzbatBatchesInfo> getList(PmHzbatBatchesInfo pmHzbatBatchesInfo) {									
			logger.info("查询用户列表");																		
			List<PmHzbatBatchesInfo> u = pmHzbatBatchesInfoMapper.getList(pmHzbatBatchesInfo);								
			return u;																						
		}																								  

		@Override																							
		public PmHzbatBatchesInfo get(PmHzbatBatchesInfo pmHzbatBatchesInfo) {											
			PmHzbatBatchesInfo u = pmHzbatBatchesInfoMapper.get(pmHzbatBatchesInfo);											
			return u;																						
		}																								  

		@Override																							
		public void add(PmHzbatBatchesInfo pmHzbatBatchesInfo) {														
			pmHzbatBatchesInfoMapper.add(pmHzbatBatchesInfo);															
		}																								  

		@Override																							
		public void update(PmHzbatBatchesInfo pmHzbatBatchesInfo) {													
			pmHzbatBatchesInfoMapper.update(pmHzbatBatchesInfo);															
		}																								  

		@Override																							
		public void delete(PmHzbatBatchesInfo pmHzbatBatchesInfo) {													
			pmHzbatBatchesInfoMapper.delete(pmHzbatBatchesInfo);															
		}																								  

		@Override																							
		public PageInfo<PmHzbatBatchesInfo> getPage(PmHzbatBatchesInfo pmHzbatBatchesInfo) {								
			return getPage(pmHzbatBatchesInfo.getPageNum(),pmHzbatBatchesInfo.getPageSize(),pmHzbatBatchesInfo);		
		}

		/***
		 * 查询计划下的所有批量，包含前后依赖关系
		 * @param pmHzbatBatchesInfo
		 * @return
		 */
		@Override
		public List<List<PmHzbatBatchesInfo>> getScheduleBatches(PmHzbatBatchesInfo pmHzbatBatchesInfo){
			List<PmHzbatBatchesInfo> startBatchs = getStartBatches(pmHzbatBatchesInfo);
			if(startBatchs == null){
				return null ;
			}
			List<List<PmHzbatBatchesInfo>> result = new ArrayList<List<PmHzbatBatchesInfo>>() ;
			for (PmHzbatBatchesInfo sb:startBatchs) {
				List<PmHzbatBatchesInfo> l = getBatchesDirection(sb);
				if(l != null){
					result.add(l);
				}
			}
			return result ;
		}
		
		
		/***
		 * 查询开始批量
		 * 
		 */
		@Override
		public List<PmHzbatBatchesInfo> getStartBatches(PmHzbatBatchesInfo pmHzbatBatchesInfo) {
			List<PmHzbatBatchesInfo> list = new ArrayList<PmHzbatBatchesInfo>();
			list = pmHzbatBatchesInfoMapper.getStartBatches(pmHzbatBatchesInfo);
			if(list.isEmpty()){
				return null ;
			}
			return list;
		}

		
		/***
		 * 根据开始批量查询该开始批量后的所有批量
		 * 
		 */
		@Override
		public List<PmHzbatBatchesInfo> getBatchesDirection(PmHzbatBatchesInfo pmHzbatBatchesInfo) {
			List<PmHzbatBatchesInfo> list = new ArrayList<PmHzbatBatchesInfo>();
			list = pmHzbatBatchesInfoMapper.getBatchesDirection(pmHzbatBatchesInfo);
			if(list.isEmpty()){
				return null ;
			}
			return list;
		}																									
}																									  


